﻿//-----------------------------------------------------------------------------
// <copyright file="TestViewElement.cs" company="William E. Kempf">
//     Copyright (c) William E. Kempf.
// </copyright>
//-----------------------------------------------------------------------------

namespace OnyxTests.TestArtifacts
{
    using System;
    using System.ComponentModel.Design;
    using System.Diagnostics.CodeAnalysis;
    using System.Windows;
    using System.Windows.Input;
    using Onyx.Windows;

    /// <summary>
    /// Provides a test class to stand in for a view element.
    /// </summary>
    [SuppressMessage("Microsoft.Design",
        "CA1001:TypesThatOwnDisposableFieldsShouldBeDisposable",
        Justification = "Just not concerned about this for a test class.")]
    public class TestViewElement : DependencyObject, IServiceProvider, IFocusSuggested
    {
        /// <summary>
        /// Provides a service container for this instance.
        /// </summary>
        private readonly ServiceContainer serviceContainer = new ServiceContainer();

        /// <summary>
        /// Provides an <see cref="ICommandTarget"/> service.
        /// </summary>
        private readonly ICommandTarget commandTarget = new CommandTargetImpl();

        /// <summary>
        /// Initializes a new instance of the <see cref="TestViewElement"/> class.
        /// </summary>
        public TestViewElement()
        {
            this.serviceContainer.AddService(typeof(ICommandTarget), this.commandTarget);
        }

        /// <summary>
        /// Gets the command target.
        /// </summary>
        /// <value>The command target.</value>
        public ICommandTarget CommandTarget
        {
            get { return this.commandTarget; }
        }

        /// <summary>
        /// Gets the service object of the specified type.
        /// </summary>
        /// <param name="serviceType">An object that specifies the type of service object to get.</param>
        /// <returns>
        /// A service object of type <paramref name="serviceType"/>.
        /// -or-
        /// null if there is no service object of type <paramref name="serviceType"/>.
        /// </returns>
        public object GetService(Type serviceType)
        {
            return this.serviceContainer.GetService(serviceType);
        }

        /// <summary>
        /// Sets the focus to an element within the "view".
        /// </summary>
        /// <param name="key">The key used to locate the element within the "view".</param>
        /// <returns>
        /// <see langword="true"/> if the element with the specified <paramref name="key"/> was found and focus was
        /// succesfully set to it; otherwise <see langword="false"/>.
        /// </returns>
        public bool SetFocus(string key)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Sets the focus to an element within the "view".
        /// </summary>
        /// <param name="key">The key used to locate the element within the "view".</param>
        /// <param name="selectAll"><see langword="true"/> if all of the contents of the selected element should be
        /// selected.</param>
        /// <returns>
        /// <see langword="true"/> if the element with the specified <paramref name="key"/> was found and focus was
        /// succesfully set to it; otherwise <see langword="false"/>.
        /// </returns>
        public bool SetFocus(string key, bool selectAll)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Provides an implementation of <see cref="ICommandTarget"/>
        /// </summary>
        private class CommandTargetImpl : ICommandTarget
        {
            /// <summary>
            /// Gets the command bindings.
            /// </summary>
            /// <value>The command bindings.</value>
            public CommandBindingCollection CommandBindings
            {
                get { throw new System.NotImplementedException(); }
            }
        }
    }
}
